//
// Created by 孟令涛 on 24-7-19.
//
#include "ADCTask.h"
#include "GlobalVars.h"

uint8_t adcConversionComplete = 0;

void ADCTask(void *argument) {
    ADC_ChannelConfTypeDef sConfig = {0};

    while (1) {
        // 配置ADC通道4
        sConfig.Channel = ADC_CHANNEL_4;
        sConfig.Rank = ADC_REGULAR_RANK_1;
        sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
        HAL_ADC_ConfigChannel(&hadc1, &sConfig);
        HAL_ADC_Start(&hadc1);
        HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
        adcValues[0] = HAL_ADC_GetValue(&hadc1);

        // 配置ADC通道5
        sConfig.Channel = ADC_CHANNEL_5;
        HAL_ADC_ConfigChannel(&hadc1, &sConfig);
        HAL_ADC_Start(&hadc1);
        HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
        adcValues[1] = HAL_ADC_GetValue(&hadc1);

        // 配置ADC通道6
        sConfig.Channel = ADC_CHANNEL_6;
        HAL_ADC_ConfigChannel(&hadc1, &sConfig);
        HAL_ADC_Start(&hadc1);
        HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
        adcValues[2] = HAL_ADC_GetValue(&hadc1);

//        // 标记转换完成
//        adcConversionComplete = 1;
//
//        // 处理采样结果
//        if (adcConversionComplete) {
//            for (int i = 0; i < NOFCHANEL; i++) {
//                volatile uint16_t temp = adcValues[i];
//                // 使用 temp 进行后续处理
//                // 例如：printf("Channel %d: %d\n", i, temp);
//            }
//            adcConversionComplete = 0;
//        }

        // 延时一段时间
        osDelay(100);
    }
}
